import sys

from .config import settings
from .utils.stop_ps import StopPs


def task_command(orin, on_type="action.sh", name=""):
    # mount_d(orin,data_name)

    # 找路径
    # _, run_path, _ = orin.exec_command("sudo find /data/ -name run.sh")
    # _, video_recorder, _ = orin.exec_command("sudo find /data/ -name video_recorder")
    # _, camera_yml, _ = orin.exec_command("sudo find /data/ -name camera_config_orin")
    # _, data_name, _ = orin.exec_command("sudo find /data/ -name {0}".format(data_name))
    # print(run_path.read().decode("utf-8"), video_recorder.read().decode("utf-8"), camera_yml.read().decode("utf-8"), data_name.read().decode("utf-8"))

    tdin, stdout, stderr = orin.exec_command("sudo sh {0}".format(on_type))

    if stderr.read().decode("utf-8"):
        print("%s采集失败：%s" % (name, stderr.read().decode("utf-8")))
        stop_ps = StopPs()
        stop_ps.kill_orin(
            ip=settings.on_01,
            ps_list=stop_ps.get_id_list(ip=settings.on_01, type=settings.ps_name),
        )

        sys.exit()
